﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Extensil.HotKeys;

namespace Extensil
{
    public partial class SetHotKey :Form
    {
        public SetHotKey(string hotKey)
        {
            InitializeComponent();
            PopulateCombos();
            if(!String.IsNullOrEmpty(hotKey))
            {
                string[] keys = hotKey.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if(keys.Length != 2)
                    return;
                SetValue(keys[0], keys[1]);
            }
        }
        void SetValue(string modifier, string key)
        {
            cbModifier.SelectedIndex = cbModifier.FindStringExact( Enum.Parse(typeof(SupportedModifiers), modifier).ToString());
            cbKey.SelectedIndex = cbKey.FindStringExact(Enum.Parse(typeof(SupportedKeys), key).ToString());
        }
        private void PopulateCombos()
        {
            cbModifier.DataSource = Enum.GetNames(typeof(SupportedModifiers));
            cbKey.DataSource = Enum.GetNames(typeof(SupportedKeys));
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            this.Tag = cbModifier.SelectedItem.ToString() + "|" + cbKey.SelectedItem.ToString();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
